<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts' // echarts theme
import resize from '@/framework/utils/mixins/resize'

require('echarts/theme/macarons')

const animationDuration = 6000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        title: {
          text: '近半年系统访问量',
          x: 'left',
          y: 'top',
          textStyle: {
            color: '#131314',
            fontSize: '16',
            fontWeight: '500'
          }
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        grid: {
          top: '12%',
          left: '2%',
          right: '2%',
          bottom: '10%',
          containLabel: true
        },
        xAxis: [{
          type: 'category',
          data: ['1月', '2月', '3月', '4月', '5月', '6月'],
          axisTick: {
            alignWithLabel: true
          },
          axisLabel: {
            textStyle: {
              color: '#86909C'
            }
          },
          axisLine: {
            // show: false,
            lineStyle: {
              color: '#E5E6EB'
            }
          }
        }],
        yAxis: [{
          type: 'value',
          axisTick: {
            show: false
          },
          splitArea: { show: false }, // 'areaStyle': { 'color': ['#fff'] }
          splitLine: { // 去除网格线
            show: true,
            lineStyle: {
              color: '#E5E8EF',
              type: 'dashed'
            }
          },
          axisLabel: {
            textStyle: {
              color: '#86909C'
            }
          },
          axisLine: {
            show: false,
            lineStyle: {
              color: '#86909C'
            }
          }
        }],
        legend: {
          left: 'center',
          bottom: '0',
          icon: 'circle',
          textStyle: {
            fontSize: 12
          },
          data: ['应用1', '应用2', '应用3']
        },
        color: ['#236EFF', '#00B2FF', '#80E1FF'],
        series: [{
          name: '应用1',
          type: 'bar',
          stack: 'vistors',
          barWidth: '30%',
          data: [79, 52, 200, 334, 390, 0],
          animationDuration,
          itemStyle: {
            show: false,
            normal: {
              areaStyle: {
                opacity: 1
              }
            }
          }

        }, {
          name: '应用2',
          type: 'bar',
          stack: 'vistors',
          barWidth: '30%',
          data: [80, 52, 200, 334, 390, 0],
          animationDuration
        }, {
          name: '应用3',
          type: 'bar',
          stack: 'vistors',
          barWidth: '30%',
          data: [30, 52, 200, 334, 390, 0],
          animationDuration,
          itemStyle: {
            barBorderRadius: [5, 5, 0, 0]
          }
        }]
      })
    }
  }
}
</script>
